package cn.db101.view;

import cn.db101.dao.bookDao;
import cn.db101.model.book;
import cn.db101.model.return_book;
import cn.db101.util.DbUtil;

import javax.swing.*;
import javax.swing.GroupLayout.Alignment;
import javax.swing.border.TitledBorder;
import javax.swing.table.DefaultTableModel;
import java.awt.*;
import java.sql.Connection;
import java.sql.ResultSet;
import java.util.Vector;

public class borrow_record_Frame{
	private static final book bk = null;
	private static final return_book ret = null;
	JFrame jf=new JFrame() ;
	private final ButtonGroup buttonGroup = new ButtonGroup();
	private JTable table;
	private DbUtil dbUtil=new DbUtil();
	

	/**
	 * Create the frame.
	 * @wbp.parser.entryPoint
	 */
	public void init() {
		jf.setResizable(false);
		jf.setTitle("\u501F\u4E66\u8BB0\u5F55");
		jf.setBounds(100, 100, 505, 653);
		
		JPanel panel = new JPanel();
		jf.getContentPane().add(panel, BorderLayout.CENTER);
		
		JPanel panel_1 = new JPanel();
		panel_1.setBackground(new Color(240, 240, 240));
		panel_1.setToolTipText("");
		panel_1.setForeground(new Color(0, 0, 0));
		panel_1.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "\u501F\u4E66\u8BB0\u5F55", TitledBorder.LEFT, TitledBorder.TOP, null, new Color(0, 0, 0)));
		
		JLabel lblNewLabel = new JLabel("");
		lblNewLabel.setIcon(new ImageIcon(borrow_record_Frame.class.getResource("/img/x.jpg")));
		GroupLayout gl_panel = new GroupLayout(panel);
		gl_panel.setHorizontalGroup(
			gl_panel.createParallelGroup(Alignment.LEADING)
				.addComponent(lblNewLabel)
				.addGroup(gl_panel.createSequentialGroup()
					.addGap(27)
					.addComponent(panel_1, GroupLayout.PREFERRED_SIZE, 442, GroupLayout.PREFERRED_SIZE))
		);
		gl_panel.setVerticalGroup(
			gl_panel.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panel.createSequentialGroup()
					.addComponent(lblNewLabel, GroupLayout.PREFERRED_SIZE, 258, GroupLayout.PREFERRED_SIZE)
					.addGap(18)
					.addComponent(panel_1, GroupLayout.PREFERRED_SIZE, 342, GroupLayout.PREFERRED_SIZE)
					.addContainerGap(58, Short.MAX_VALUE))
		);
		
		JScrollPane scrollPane = new JScrollPane();
		GroupLayout gl_panel_1 = new GroupLayout(panel_1);
		gl_panel_1.setHorizontalGroup(
			gl_panel_1.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panel_1.createSequentialGroup()
					.addContainerGap()
					.addComponent(scrollPane, GroupLayout.DEFAULT_SIZE, 402, Short.MAX_VALUE)
					.addContainerGap())
		);
		gl_panel_1.setVerticalGroup(
			gl_panel_1.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panel_1.createSequentialGroup()
					.addGap(25)
					.addComponent(scrollPane, GroupLayout.PREFERRED_SIZE, 216, GroupLayout.PREFERRED_SIZE)
					.addContainerGap(74, Short.MAX_VALUE))
		);
		
		table = new JTable();
		table.setModel(new DefaultTableModel(
			new Object[][] {
			},
			new String[] {
				"\u8BFB\u8005\u53F7", "\u4E66\u540D", "\u501F\u4E66\u65E5\u671F", "\u8FD8\u4E66\u65E5\u671F"
			}
		) {
			boolean[] columnEditables = new boolean[] {
				false, true, true, true
			};
			public boolean isCellEditable(int row, int column) {
				return columnEditables[column];
			}
		});
		scrollPane.setViewportView(table);
		panel_1.setLayout(gl_panel_1);
		panel.setLayout(gl_panel);
		//���ô���ɼ�
		jf.setVisible(true);	
		//����JFrame������ʾ
		jf.setLocationRelativeTo(null);
		fillTable();
	}
	/**
	 * ��ʼ�����
	 * @param bk 
	 * @param ret 
	 * @param bookType
	 */
	private void fillTable() {
		DefaultTableModel dtm=(DefaultTableModel) table.getModel(); 
		dtm.setRowCount(0);//���ó�0��
		Connection con=null;
		try {
			con=dbUtil.getCon();
			ResultSet rs= bookDao.record(con);
			while(rs.next()) {
				Vector v=new Vector();
				v.add(rs.getString("reader_no"));
				v.add(rs.getString("book_name"));
				v.add(rs.getDate("borrow_start_time"));
				v.add(rs.getDate("return_time"));
				dtm.addRow(v);
			}
		}catch(Exception e) {
			e.printStackTrace();
		}finally {
			try {
				dbUtil.closeCon(con);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
}
